package com.kmproject.haifu.mvp.ui.adapter;

import android.content.res.Resources;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.ui.holder.SxSelectHolderNew;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.List;

public class PopuWindowSelectSxNewAdapter extends BaseQuickAdapter<HousePayWayBean, BaseViewHolder> {
    public SxSelectHolderNew.selectCallBack mselectCallBack;
    public PopuWindowSelectSxNewAdapter(SxSelectHolderNew.selectCallBack selectCallBack, @Nullable List<HousePayWayBean> data) {
        super(R.layout.housepublic_item, data);
        mselectCallBack=selectCallBack;
    }

    @Override
    protected void convert(BaseViewHolder helper, HousePayWayBean item) {
     helper.<TextView>getView(R.id.housepublic_item_tv).setText(item.getName());
//        helper.<RecyclerView>getView(R.id.housepublic_item_RecyclerView).addItemDecoration(new SpaceItemDecoration(dp2px(2)));
        helper.<RecyclerView>getView(R.id.housepublic_item_RecyclerView).setLayoutManager(new GridLayoutManager(mContext,4));
        helper.<RecyclerView>getView(R.id.housepublic_item_RecyclerView).setAdapter(new PopuWindowSelectSxItemNewAdapter(item.getCode(), item.getChildren(), new PopuWindowSelectSxItemNewAdapter.ItemClickCallBack() {
            @Override
            public void callback(int position, HousePayWayBean housePayWayBean) {
               if (housePayWayBean.getChildren()!=null&&!housePayWayBean.getChildren().isEmpty())
               {
                   mselectCallBack.callBack(housePayWayBean);
               }else {
                   mselectCallBack.callBack(null);
               }
            }
        }));
    }
    public  int dp2px(float dpValue) {
        return (int) (0.5f + dpValue * Resources.getSystem().getDisplayMetrics().density);
    }
}
